{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<div style=\"color:#777777;background-color:#ffffff;font-size:12px;text-align:right;\">\n",
    "\tprepared by Abuzer Yakaryilmaz (QuSoft@Riga) | November 10, 2018\n",
    "</div>\n",
    "<table><tr><td><i> I have some macros here. If there is a problem with displaying mathematical formulas, please run me to load these macros.</i></td></td></table>\n",
    "$ \\newcommand{\\bra}[1]{\\langle #1|} $\n",
    "$ \\newcommand{\\ket}[1]{|#1\\rangle} $\n",
    "$ \\newcommand{\\braket}[2]{\\langle #1|#2\\rangle} $\n",
    "$ \\newcommand{\\inner}[2]{\\langle #1,#2\\rangle} $\n",
    "$ \\newcommand{\\biginner}[2]{\\left\\langle #1,#2\\right\\rangle} $\n",
    "$ \\newcommand{\\mymatrix}[2]{\\left( \\begin{array}{#1} #2\\end{array} \\right)} $\n",
    "$ \\newcommand{\\myvector}[1]{\\mymatrix{c}{#1}} $\n",
    "$ \\newcommand{\\myrvector}[1]{\\mymatrix{r}{#1}} $\n",
    "$ \\newcommand{\\mypar}[1]{\\left( #1 \\right)} $\n",
    "$ \\newcommand{\\mybigpar}[1]{ \\Big( #1 \\Big)} $\n",
    "$ \\newcommand{\\sqrttwo}{\\frac{1}{\\sqrt{2}}} $\n",
    "$ \\newcommand{\\dsqrttwo}{\\dfrac{1}{\\sqrt{2}}} $\n",
    "$ \\newcommand{\\onehalf}{\\frac{1}{2}} $\n",
    "$ \\newcommand{\\donehalf}{\\dfrac{1}{2}} $\n",
    "$ \\newcommand{\\hadamard}{ \\mymatrix{rr}{ \\sqrttwo & \\sqrttwo \\\\ \\sqrttwo & -\\sqrttwo }} $\n",
    "$ \\newcommand{\\vzero}{\\myvector{1\\\\0}} $\n",
    "$ \\newcommand{\\vone}{\\myvector{0\\\\1}} $\n",
    "$ \\newcommand{\\vhadamardzero}{\\myvector{ \\sqrttwo \\\\  \\sqrttwo } } $\n",
    "$ \\newcommand{\\vhadamardone}{ \\myrvector{ \\sqrttwo \\\\ -\\sqrttwo } } $\n",
    "$ \\newcommand{\\myarray}[2]{ \\begin{array}{#1}#2\\end{array}} $\n",
    "$ \\newcommand{\\X}{ \\mymatrix{cc}{0 & 1 \\\\ 1 & 0}  } $\n",
    "$ \\newcommand{\\Z}{ \\mymatrix{rr}{1 & 0 \\\\ 0 & -1}  } $\n",
    "$ \\newcommand{\\Htwo}{ \\mymatrix{rrrr}{ \\frac{1}{2} & \\frac{1}{2} & \\frac{1}{2} & \\frac{1}{2} \\\\ \\frac{1}{2} & -\\frac{1}{2} & \\frac{1}{2} & -\\frac{1}{2} \\\\ \\frac{1}{2} & \\frac{1}{2} & -\\frac{1}{2} & -\\frac{1}{2} \\\\ \\frac{1}{2} & -\\frac{1}{2} & -\\frac{1}{2} & \\frac{1}{2} } } $\n",
    "$ \\newcommand{\\CNOT}{ \\mymatrix{cccc}{1 & 0 & 0 & 0 \\\\ 0 & 1 & 0 & 0 \\\\ 0 & 0 & 0 & 1 \\\\ 0 & 0 & 1 & 0} } $\n",
    "$ \\newcommand{\\norm}[1]{ \\left\\lVert #1 \\right\\rVert } $"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h2>Grover's Search</h2>\n",
    "\n",
    "Grover's search algorithm is one of the well-known quantum algorithms.\n",
    "\n",
    "It finds a marked element in an unsorted list quadratically better than the classical algorithms.\n",
    "\n",
    "Grover's search algorithm iteratively applies two reflections.\n",
    "\n",
    "Its implementation is complicated, but its explanation is easy.\n",
    "\n",
    "Here, we describe Grover's search algorithm, and then emulate it on the unit circle. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h3> Representation of data </h3>\n",
    "\n",
    "Suppose that we have 16 elements in our list.\n",
    "\n",
    "The list has marked and unmarked elements. (A marked element refers to a searching item.)\n",
    "\n",
    "Each quantum state will be associated with a different index of the list.\n",
    "\n",
    "Four qubits have 16 different states ($ \\ket{0000}, \\ldots, \\ket{1111} $), and so we use 4 qubits.\n",
    "\n",
    "We assume that when we keep the whole list \"quantumly\", we can check whether an item is marked or not in a single step by using its index.\n",
    "\n",
    "For example, if the element associated with the state $ \\ket{1101} $ is marked, then we can detect this by changing the sign of this state.\n",
    "\n",
    "We remind that changing the sign of a quantum state is one of the basic opearations.\n",
    "\n",
    "<i>In general, if we have a list of size $ 2^k $, then we can use $ k $ qubits and associate each state with one of the item in the list.</i>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h3>Search in parallel</h3>\n",
    "\n",
    "We can access each element in the list with one of the basis states.\n",
    "\n",
    "We start in state $ \\ket{0000} $.\n",
    "\n",
    "Then, we apply Hadamard to each qubit.\n",
    "\n",
    "Remember that $ \\ket{0000} = \\ket{0} \\otimes \\ket{0} \\otimes \\ket{0} \\otimes \\ket{0}  $, or equivalently $ \\ket{0000} = \\ket{0}\\ket{0}\\ket{0}\\ket{0} $ by omitting tensor symbol.\n",
    "\n",
    "After Hadamard operator, our quantum state is\n",
    "\n",
    "$ \\ket{u} = H\\ket{0} \\otimes H\\ket{0} \\otimes H\\ket{0} \\otimes H\\ket{0} $, which is\n",
    "\n",
    "$$\n",
    "    \\ket{u} =\n",
    "    \\mypar{ \\frac{1}{\\sqrt{2}} \\ket{0} + \\frac{1}{\\sqrt{2}} \\ket{1}  } \\otimes\n",
    "    \\mypar{ \\frac{1}{\\sqrt{2}} \\ket{0} + \\frac{1}{\\sqrt{2}} \\ket{1}  } \\otimes\n",
    "    \\mypar{ \\frac{1}{\\sqrt{2}} \\ket{0} + \\frac{1}{\\sqrt{2}} \\ket{1}  } \\otimes\n",
    "    \\mypar{ \\frac{1}{\\sqrt{2}} \\ket{0} + \\frac{1}{\\sqrt{2}} \\ket{1}  }.\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "From this tensor product, we can get every basis state of 4 qubits having the amplitude $ \\frac{1}{4} $:\n",
    "\n",
    "\n",
    "$$\n",
    "   \\ket{u}= \\frac{1}{4} \\ket{0000} + \\frac{1}{4} \\ket{0001} +  \\frac{1}{4} \\ket{0010} +  \\frac{1}{4} \\ket{0011} \n",
    "   + \\cdots \\cdots +  \\frac{1}{4} \\ket{1101}  +  \\frac{1}{4} \\ket{1110} +  \\frac{1}{4} \\ket{1111}.\n",
    "$$\n",
    " "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Thus, after Hadamard, we can access each index in parallel, \n",
    "<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n",
    "because we are in <u>a superposition of all basis states</u>, or in <u>a superposition of all indices of the list</u>.\n",
    "\n",
    "However, the probability of observing any basis state at this moment is exponentially small: $ \\frac{1}{16} $. \n",
    "\n",
    "(It is $ \\frac{1}{2^k} $ if there are $ 2^k $ elements.)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h3> Task 1 </h3>\n",
    "\n",
    "Design a quantum circuit with 4 qubits.\n",
    "\n",
    "Apply Hadamard to each qubit.\n",
    "\n",
    "Execute your circuit 1600 times.\n",
    "\n",
    "You should observe each basis state around 100 times.\n",
    "\n",
    "Reexecute your circuit 16000 times."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# import all necessary objects and methods for quantum circuits\n",
    "from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit, execute, Aer\n",
    "from qiskit.tools.visualization import matplotlib_circuit_drawer as drawer\n",
    "\n",
    "#\n",
    "# your solution is here\n",
    "#\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a href=\"..\\bronze-solutions\\B88_Grovers_Search_Solutions.ipynb#task1\">click for our solution</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h3> Unit circle representation</h3>\n",
    "\n",
    "For representing quantum state $ \\ket{u} $, we need 16-dimensional space.\n",
    "\n",
    "But, we can map $\\ket{u} $ to 2-dimensional space.\n",
    "\n",
    "We have marked elements and unmarket elements. \n",
    "\n",
    "We can group the states associated with marked elements and the state associated with unmarked elements.\n",
    "\n",
    "Then, we can represent $ \\ket{u} $ as a summation of two quantum states $ \\ket{u} = a \\ket{u_{marked}} + b \\ket{u_{unmarked}} $.\n",
    "\n",
    "The states in $ \\ket{u_{marked}} $ and $ \\ket{u_{unmarked}} $ are different from each other.\n",
    "\n",
    "Therefore, they are orthogonal to each other. We can represent $ \\ket{u} = a \\ket{u_{marked}} + b \\ket{u_{unmarked}} $ in 2-dimension as below:"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img src=\"../images/marked-unmarked.jpg\" width=\"40%\"> "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Remark that if all elements are marked, then $ \\ket{u} = \\ket{u_{marked}} $, and if all elements are unmarked, then $ \\ket{u} = \\ket{u_{unmarked}}$.\n",
    "\n",
    "For example, if we have 3 marked elements in our example, then we can find our parameters as follows.\n",
    "\n",
    "Let the marked states be $ \\ket{marked1} , \\ket{marked2} , \\ket{marked3} $.\n",
    "\n",
    "Let the unmarked states be $ \\ket{unmarked1} , \\ket{unmarked2} , \\ldots, \\ket{unmarked13} $.\n",
    "\n",
    "In $ \\ket{u} $, each of this state has the amplitude $ \\frac{1}{\\sqrt{16}} $:\n",
    "\n",
    "$$\n",
    "    \\ket{u} = \\frac{1}{\\sqrt{16}} \\mypar{ \\ket{marked1} + \\ket{marked2} + \\ket{marked3} } +\n",
    "            \\frac{1}{\\sqrt{16}} \\mypar{  \\ket{unmarked1} + \\ket{unmarked2} + \\cdots + \\ket{unmarked13} }\n",
    "$$\n",
    "\n",
    "Then, our parameters are\n",
    "<ul>\n",
    "    <li>  $ \\ket{u_{marked}} = \\frac{1}{\\sqrt{3}} \\mypar{ \\ket{marked1} + \\ket{marked2} + \\ket{marked3} } $ and </li>\n",
    "    <li>  $ a = \\frac{\\sqrt{3}}{\\sqrt{16}} $; and, </li>\n",
    "    <li>  $ \\ket{u_{unmarked}} = \\frac{1}{\\sqrt{13}} \\mypar{ \\ket{unmarked1} + \\ket{unmarked2} + \\cdots + \\ket{unmarked13} } $ and </li>\n",
    "    <li>  $ b = \\frac{\\sqrt{13}}{\\sqrt{16}} $. </li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The idea here is to select $ \\ket{u_{marked}} $ and $\\ket{u_{unmarked}} $ as quantum states, i.e., their lengths should be 1. \n",
    "\n",
    "In this way, we can also keep the ratio of $ \\frac{3}{13} $ as ratio of\n",
    "<ul>\n",
    "    <li> the probability of observing a state in $ \\ket{u_{marked}} $ and </li>\n",
    "    <li> the probability of observing a state in $ \\ket{u_{unmarked}} $. </li>\n",
    "</ul>\n",
    "\n",
    "Remark that the first probability is $ a^2 = \\frac{3}{16} $ and the second probability if $ b^2 = \\frac{13}{16} $."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<i> So, in general, if we have $ 2^k $ elements and $ m $ of them are marked, then $ a = \\frac{\\sqrt{m}}{\\sqrt{2^k}} $ and  $ b= \\frac{\\sqrt{2^k - m}}{\\sqrt{2^k}} $. </i>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h3>The idea behind Grover's search</h3>\n",
    "\n",
    "The idea behind Grover's search algorithm is that \n",
    "<ul>\n",
    "    <li> the amplitudes of the marked elements can be quickly amplified, </li>\n",
    "    <li> and so the probability of observing one of the marked element quickly approches to 1.</li>\n",
    "</ul>\n",
    "\n",
    "For \"quick\" amplification, we iteratively applies two reflections to our quantum states. \n",
    "\n",
    "The first reflection is a clockwise rotation, and the second rotation is counterclockwise. \n",
    "\n",
    "The second rotation always rotates twice of the first rotation. \n",
    "\n",
    "Therefore, our quantum state moves counterclockwise direction after two reflections."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "As an analogy, we consider the rotation on the unit circle with angle $ \\frac{\\pi}{8} $ that starts in $ \\ket{0} $. \n",
    "<ul>\n",
    "    <li> After every 4 rotations, we visit in order $ \\ket{1} $, $ -\\ket{0} $, $ -\\ket{1} $, again $ \\ket{0} $, and so on. </li>\n",
    "    <li> Remark that the probability of observing the state $ \\ket{1} $ oscillates between increasing and decreasing while rotating. </li>\n",
    "</ul>\n",
    "\n",
    "Similarly, when iterating Grover's search algorithm, we should be careful when to stop. \n",
    "<ul>\n",
    "    <li> Because, after hitting a maximum value, these amplitudes are quickly decreased, and after hitting a minimum value, they are amplified again, and so on.</li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h3> One iteration of the algorithm </h3>\n",
    "\n",
    "Once we have the unit circle representation, then we can describe the algorithm very easily.\n",
    "\n",
    "Grover's search algorithm simply iterates two reflection, which can be implemented as two rotations.\n",
    "\n",
    "The axis of the first reflection is the quantum state $ \\ket{u_{unmarked}} $.\n",
    "\n",
    "The axis of the second reflection is the first quantum state after Hadamard operators: $ \\ket{u} $.\n",
    "\n",
    "During all iterations, these axes are fixed. \n",
    "\n",
    "Remark that both of them depend on only the list and marked/unmarked elements."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img src=\"../images/reflection_axes.jpg\" width=\"70%\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<b> Grover's search algorithm: </b>\n",
    "\n",
    "Start in $ \\ket{u} $.\n",
    "\n",
    "Iteratively:\n",
    "<ol>\n",
    "    <li>Reflection over the first axis: Flip the sign of the states associated with the marked elements.\n",
    "    </li> \n",
    "    <li>Reflection over the second axis: Then, reflect the resulting quantum state over the $\\ket{u}$-axis.\n",
    "    </li>\n",
    "</ol>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "After the first reflection: the current quantum state rotates with angle $ -2 \\theta $.\n",
    "\n",
    "<img src=\"../images/grover_first_reflection.jpg\" width=\"70%\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "After the second reflection: the reflected state rotates with angle $ 4 \\theta $.\n",
    "\n",
    "<img src=\"../images/grover_second_reflection.jpg\" width=\"70%\">\n",
    "\n",
    "Then, the angle of the new quantum state is $ 3 \\theta $."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The second iteration:\n",
    "<ul>\n",
    "    <li> The angle of the new quantum state is $ 3 \\theta $. </li>\n",
    "    <li> After the first reflection (rotation by $ -6 \\theta $): The reflected quantum state has angle $ -3 \\theta $. </li>\n",
    "    <li> The angle between the reflected quantum state and the second reflection axis is $ 4 \\theta $.\n",
    "    <li> With the second reflection, the reflected quantum state rotates $ 8 \\theta $.</li>\n",
    "    <li> Thus, the angle of the newest state will be $ 5\\theta $. </li>\n",
    "</ul>\n",
    "\n",
    "<b>Hence after each iteration the angle of the quantum state will be increased by $ 2 \\theta $.</b>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In this way, the quantum state iteratively approaches to $ \\ket{u_{marked}} $.\n",
    "\n",
    "If we do not stop the iterations, then it passes  $ \\ket{u_{marked}} $, and starts to approaches $ - \\ket{u_{unmarked}} $.\n",
    "\n",
    "If the quantum state is sufficiently close to $ \\ket{u_{marked}} $ and we make a measurement, we can observe a marked element with high probability.\n",
    "\n",
    "This is also the place to stop the iterations."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h3> Task 2: Emulating Grover's search </h3>\n",
    "\n",
    "For this task, you can use the methods given in notebook <a href=\"B80_Reflections.ipynb\" target=\"_blank\">B80_Reflections</a>.\n",
    "\n",
    "Set the value of $ k $ to 4. Then, the size of list is $ 2^k = 16 $.\n",
    "\n",
    "Pick the value of $ m $ as 3, the number of the marked elements.\n",
    "\n",
    "As described above, $ \\ket{u} = \\sqrt{\\frac{3}{16}} \\ket{u_{marked}} + \\sqrt{\\frac{13}{16}} \\ket{u_{unmarked}} $.\n",
    "\n",
    "Create a quantum circuit with single qubit.\n",
    "\n",
    "States $ \\ket{1} $ and $ \\ket{0} $ represents the quantum state $ \\ket{u_{marked}} $ and $ \\ket{u_{unmarked}}$, respectively.\n",
    "\n",
    "Then, $ \\ket{u} = \\sqrt{\\frac{13}{16}} \\ket{0} + \\sqrt{\\frac{3}{16}} \\ket{1} $.\n",
    "\n",
    "<b>Determine the angle $ \\theta $, the angle between $ \\ket{u} $ and $ \\ket{0} $.</b>\n",
    "\n",
    "<b>Iterate Grover's search algorithm once by using your quantum circuit.</b>\n",
    "\n",
    "For each reflection, use ry-gate (rotation).\n",
    "<ul>\n",
    "    <li> Define a list to store all quantum states (with their labels) that will be visited.</li>\n",
    "    <li> Implement the first reflection on your qubit </li>\n",
    "    <li> Read the current quantum state and store it on your list </li>\n",
    "    <li> Implement the second reflection on your qubit </li>\n",
    "    <li> Read the current quantum state and store it on your list</li>\n",
    "    <li> Draw all visited quantum states with their labels </li>\n",
    "    <li> Execute your circuit 100 times </li>\n",
    "</ul>\n",
    "\n",
    "Is this single iteration enough to observe state $ \\ket{1} $ more than state $ \\ket{0} $? "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#\n",
    "# your solution\n",
    "#\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a href=\"..\\bronze-solutions\\B88_Grovers_Search_Solutions.ipynb#task2\">click for our solution</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h3> Taks 3 </h3>\n",
    "\n",
    "For this task, you can use the methods given in notebook <a href=\"B80_Reflections.ipynb\" target=\"_blank\"> B80_Reflections </a>.\n",
    "\n",
    "Set the value of $ k $ to 6. Then, the size of list is $ 2^k = 64 $.\n",
    "\n",
    "Pick the value of $ m $ as 1, the number of the marked elements.\n",
    "\n",
    "As described above, $ \\ket{u} = \\sqrt{\\frac{1}{64}} \\ket{u_{marked}} + \\sqrt{\\frac{63}{64}} \\ket{u_{unmarked}} $.\n",
    "\n",
    "Create a quantum circuit with single qubit.\n",
    "\n",
    "States $ \\ket{1} $ and $ \\ket{0} $ represents the quantum state $ \\ket{u_{marked}} $ and $ \\ket{u_{unmarked}}$, respectively.\n",
    "\n",
    "Then, $ \\ket{u} = \\sqrt{\\frac{63}{64}} \\ket{0} + \\sqrt{\\frac{1}{64}} \\ket{1} $.\n",
    "\n",
    "<b>Determine the angle $ \\theta $, the angle between $ \\ket{u} $ and $ \\ket{0} $.</b>\n",
    "\n",
    "<b>Iterate Grover's search algorithm <u>three times</u> by using your quantum circuit.</b>\n",
    "\n",
    "For each reflection, use ry-gate (rotation).\n",
    "<ul>\n",
    "    <li> Define a list to store all quantum states (with their labels) that will be visited.</li>\n",
    "    <li> Iterate 3 times:\n",
    "        <ul>\n",
    "            <li> Implement the first reflection on your qubit </li>\n",
    "            <li> Read the current quantum state and store it on your list </li>\n",
    "            <li> Implement the second reflection on your qubit </li>\n",
    "            <li> Read the current quantum state and store it on your list</li>\n",
    "        </ul> </li>\n",
    "    <li> Draw all visited quantum states with their labels </li>\n",
    "    <li> Execute your circuit 100 times </li>\n",
    "</ul>\n",
    "\n",
    "Is 3 iterations enough to observe state $ \\ket{1} $ more than state $ \\ket{0} $?\n",
    "\n",
    "Try 4, 5, 6, 7, 8, 9, and 10 iterations.\n",
    "\n",
    "What is the best iteration number?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#\n",
    "# your code is here\n",
    "#\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a href=\"..\\bronze-solutions\\B88_Grovers_Search_Solutions.ipynb#task3\">click for our solution</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h3> Task 4 </h3>\n",
    "\n",
    "Repeat Task 3 for $ k = 8 $ and $ m = 1 $, but algorithmically find the best iteration number, say $B$. \n",
    "\n",
    "You may execute your circuit 1000 times to have more reliable results.\n",
    "<hr>\n",
    "<i> Hint:\n",
    "\n",
    "For each iteration number, you may check how many times the state $ \\ket{1} $ is observed. \n",
    "<br><br>\n",
    "This value should be at least 500.\n",
    "\n",
    "And, when this value starts to decrease, you may announce the previous iteration number as the best. \n",
    "</i>\n",
    "<hr>\n",
    "Our solution outputs $ B $ as 12 in every execution."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a href=\"..\\bronze-solutions\\B88_Grovers_Search_Solutions.ipynb#task4\">click for our solution</a>"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
